package com.xxx.util;

import java.util.List;

//pageNum 页码
//pageSize 每页多少条数据
public class pageUtil {
    public pageUtil() {
    }

    public Integer getPageCount(List list){
        return list.size();
    }
    public static List startPage(List list,Integer pageNum,Integer pageSize){
        if (list==null){
            return null;
        }
        if (list.size()==0){
            return null;
        }
        Integer count = list.size();//记录总条数
        Integer pageCount=0;//页数
        if (count%pageSize==0){
            pageCount=count/pageSize;
        }else {
            pageCount=count/pageSize+1;
        }
        int fromIndex=0;//开始位置
        int toIndex=0;//结束位置
        if (!pageNum.equals(pageCount)){
            fromIndex=(pageNum-1)*pageSize;
            toIndex=fromIndex+pageSize;
        }else {
            fromIndex=(pageNum-1)*pageSize;
            toIndex=count;
        }
        List pageList=list.subList(fromIndex,toIndex);
        return pageList;
    }
}
